import uvicorn
from fastapi import FastAPI, WebSocket

app = FastAPI()

@app.websocket("/api")
async def api(websocket: WebSocket):
    await websocket.accept()
    while True:
        data = await websocket.receive_json()
        print("客户端的数据:::", data)
        await websocket.send_json(f"答案是： {data['message']}")

if __name__ == '__main__':
    uvicorn.run('ws:app', host='0.0.0.0', port=8088)


